<?php
namespace Home\Controller;
use Think\Controller;
class NewsController extends Controller {

    public function news(){
        $nav=M('nav')->select();
        $this->assign('nav',$nav);
        if(!empty($aid) && $aid==9999){
            //所有文章
            $aid=I('get.aid');
            $article=M('article')->order('art_pageview DESC')->select();
            $this->assign('article',$article);
        }else{
            //分页
            //每页显示的数据
            $limit=5;
            //查询数据总数
            $count=M('article')->count();
            //调用TP分页类
            $page=new \Think\Page($count,$limit);
            //生成分页
            $show=$page->show();
            //查询数据
            $article=M('article')
                ->where("is_show=1")
                ->order('art_pageview DESC')
                ->limit($page->firstRow.','.$page->listRows)
                ->select();
            //裁剪文章内容
            foreach($article as $v){
                $cut=str_cut($v['art_content'],0,120);
                $decut=htmlspecialchars_decode($cut);
                $content[]=$decut;
            }
            $b=0;
            $this->assign('b',$b);
            $this->assign('content',$content);
            $this->assign('show',$show);
            $this->assign('article',$article);
            $this->assign('a',$page->firstRow+1);
            //右侧推荐
            $Recommend=M('article')->where("is_show=1")->order('art_pageview DESC')->limit(5)->select();
            $this->assign('Recommend',$Recommend);
            //配置
            $icp=M('config')->where("con_title='备案号'")->find();
            $this->assign('icp',$icp);
            $logo=M('config')->where("con_title='logo'")->find();
            $this->assign('logo',$logo);
            $banner=M('banner')->where("banner_position=2 and banner_title='新闻'")->find();
            $this->assign('banner',$banner);
        }

        $this->display();
    }
}